package service

import (
	"ksd-social-api/commons/page"
	cmodel "ksd-social-api/modules/special/model"
	cvo "ksd-social-api/modules/special/model/vo"
	"ksd-social-api/modules/user/model/context"
	"ksd-social-api/utils"
)

/**
 * 我的专题
 * @author feige
 * @date 2023-12-14
 * @version 1.0
 * @desc
 */
func (service *UserCenterService) FindMySpecialPage(ctx context.UserCenterContext) *page.Page {
	specialPage, _ := specialMapper.FindMySpecialsPage(ctx.UserId, ctx.SystemId, ctx.PageNo, ctx.PageSize)
	specialList := specialPage.Records.([]cmodel.Special)
	if specialList != nil {
		specialDetailVos := []cvo.SpecialDetailVo{}
		for _, special := range specialList {
			specialVo := cvo.SpecialDetailVo{}
			utils.CopyProperties(&specialVo, special)
			specialDetailVos = append(specialDetailVos, specialVo)
		}
		specialPage.Records = specialDetailVos
	}
	return specialPage
}

/**
 * 我的浏览记录专题
 * @author feige
 * @date 2023-12-14
 * @version 1.0
 * @desc
 */
func (service *UserCenterService) FindMySpecialBroswerPage(ctx context.UserCenterContext) *page.Page {
	specialPage, _ := specialMapper.FindMySpecialsBroswerPage(ctx.UserId, ctx.SystemId, ctx.PageNo, ctx.PageSize)
	specialList := specialPage.Records.([]cmodel.Special)
	if specialList != nil {
		specialDetailVos := []cvo.SpecialDetailVo{}
		for _, special := range specialList {
			specialVo := cvo.SpecialDetailVo{}
			utils.CopyProperties(&specialVo, special)
			specialDetailVos = append(specialDetailVos, specialVo)
		}
		specialPage.Records = specialDetailVos
	}
	return specialPage
}

/**
 * 收藏的专题
 * @author feige
 * @date 2023-12-14
 * @version 1.0
 * @desc
 */
func (service *UserCenterService) FindSpecialUserFavPage(ctx context.UserCenterContext) *page.Page {
	specialPage, _ := specialUserFavMapper.FindSpecialUserFavPage(ctx.UserId, ctx.SystemId, ctx.PageNo, ctx.PageSize)
	specialList := specialPage.Records.([]cmodel.Special)
	if specialList != nil {
		specialDetailVos := []cvo.SpecialDetailVo{}
		for _, special := range specialList {
			specialVo := cvo.SpecialDetailVo{}
			utils.CopyProperties(&specialVo, special)
			specialDetailVos = append(specialDetailVos, specialVo)
		}
		specialPage.Records = specialDetailVos
	}
	return specialPage
}

/**
 * 喜欢的专题
 * @author feige
 * @date 2023-12-14
 * @version 1.0
 * @desc
 */
func (service *UserCenterService) FindSpecialUserLikePage(ctx context.UserCenterContext) *page.Page {
	specialPage, _ := specialUserLikeMapper.FindSpecialUserLikePage(ctx.UserId, ctx.SystemId, ctx.PageNo, ctx.PageSize)
	specialList := specialPage.Records.([]cmodel.Special)
	if specialList != nil {
		specialDetailVos := []cvo.SpecialDetailVo{}
		for _, special := range specialList {
			specialVo := cvo.SpecialDetailVo{}
			utils.CopyProperties(&specialVo, special)
			specialDetailVos = append(specialDetailVos, specialVo)
		}
		specialPage.Records = specialDetailVos
	}
	return specialPage
}

/**
 * 取消专题收藏
 * @author feige
 * @date 2024-01-13
 * @version 1.0
 * @desc
 */
func (service *UserCenterService) CancelFavSpecial(userId uint64, specialId uint64, systemId uint64) bool {
	return specialUserFavMapper.CancelSpecialUserFav(userId, specialId, systemId)
}

/**
 * 取消专题点赞
 * @author feige
 * @date 2024-01-13
 * @version 1.0
 * @desc
 */
func (service *UserCenterService) CanceLikeSpecial(userId uint64, specialId uint64, systemId uint64) bool {
	return specialUserLikeMapper.CancelSpecialUserLike(userId, specialId, systemId)
}

/**
 * 删除专题浏览记录
 * @author feige
 * @date 2024-01-13
 * @version 1.0
 * @desc
 */
func (service *UserCenterService) RemoveSpecialHits(userId uint64, specialId uint64, systemId uint64) bool {
	return specialMapper.RemoveSpecialHits(userId, specialId, systemId)
}
